package cn.snowheart.iterator.menu;

import cn.snowheart.iterator.iterator.ArrayIterator;

import java.util.Iterator;

/**
 * 煎饼店菜单
 *
 * @author liuwanxiang
 * @version 2019/07/09
 */
public class PancakeMenu implements Menu {

    private MenuItem[] menus;
    private static int MAX_SIZE = 6;
    private int currentSize;

    public PancakeMenu() {
        menus = new MenuItem[MAX_SIZE];
        currentSize = 0;

        add(new MenuItem("Pancake1", "Milk", true, 0.99));
        add(new MenuItem("Pancake2", "Cake", true, 1.99));
        add(new MenuItem("Pancake3", "Egg.", true, 0.39));
        add(new MenuItem("Pancake4", "Fruit", true, 1.49));
    }

    @Override
    public Iterator<MenuItem> createIterator() {
        return new ArrayIterator<>(menus);
    }

    @Override
    public void add(MenuItem item) {
        if (currentSize < MAX_SIZE - 1) {
            menus[currentSize++] = item;
        }
    }
}
